﻿using MathNet.Numerics.LinearAlgebra;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MathNetDemo.Startup
{
    internal class Stage_02_Arithmetics
    {

        void Run()
        { 
            // create a dense matrix with 3 rows and 4 columns
            // filled with random numbers sampled from the standard distribution
            Matrix<double> m = Matrix<double>.Build.Random(3, 4);
            // create a dense zero-vector of length 10
            Vector<double> v = Vector<double>.Build.Dense(10);

            var v2 = m.Multiply(v);
            var m2 = m.Add(m.Multiply(2));

            ///最后的参数为 结果接收者
            m.Multiply(v, v);              //  v <- m*v
            m.Multiply(3, m);       //  m <- 3*m

            //-----------------------------
            //简化方法  常用的 矩阵转置并且乘以 
            //(X.Transpose() * X).Inverse() * (X.Transpose() * y)
            //X.TransposeThisAndMultiply(X).Inverse() * X.TransposeThisAndMultiply(y)
            //也可以用分解法
            //X.TransposeThisAndMultiply(X).Cholesky().Solve(X.TransposeThisAndMultiply(y))
            //如果问题足够简单 可直接解开
            //X.Solve(y);
        }

    }
}
